<?php 
// 1. 총일수 구하기
$last_day = date("t", time());
// 2. 시작요일 구하기
$start_week = date("w", strtotime($param['yymm']."-01"));
// 3. 총 몇 주인지 구하기
$total_week = ceil(($last_day + $start_week) / 7);
// 4. 마지막 요일 구하기
$last_week = date('w', strtotime($param['yymm']."-".$last_day));

$arr = explode('-',$param['yymm']);
$current_year = $arr[0];
$current_month = $arr[1];
$crrent_time = mktime(0,0,0,$current_month,1,$current_year);
$prev = date('Y-m',strtotime("-1 month",$crrent_time));
$next = date('Y-m',strtotime("+1 month",$crrent_time));

?>
<style type="text/css">
	a.btnDelete img{display:none;}
</style>
<script type="text/javascript">
//<![CDATA[ 
    function frmValid(){
		with(document.frmReg){
			if(checkEmpty(title)){
				alert("제목을 입력해주세요");
				title.focus();
				return;
			}
			submit();
		}
    }

    function frmDelete(){
		if(!confirm('삭제 하시겠습니까?'))return;
		with(document.frmReg){
			dbjob.value = 'd';
			submit();
		}	 
	}
           
	function register(dt){
		$("[name=schedule_date]").val(dt);
		$("html,body").css("overflow","hidden");
		$("#layerBg").show();
		$(".layer_event").show();
	}

	function modify(id){
		$.ajax({
			type: "GET",
			url: "/schedule/ajax_get_schedule",
			data: "id="+id,
			success: function(data){

				var rst = eval('('+data+')');
				with(document.frmReg){
					dbjob.value = 'u';
					id.value = rst.id;
					title.value = rst.title;
					//schedule_date.value = rst.schedule_date;
					schedule_time.value =  rst.schedule_time;			
					content.value =  rst.content.replace(/<br>/gi,'\r\n');
				}
				register(rst.schedule_date);
				$("a.btnDelete img").show();
			},
			error:function(error){alert('에러1');}
		});
	}
//]]>
</script>
<div class="box_type02">
	<h2 class="txt">행사관리</h2>
	<p class="icon"><a href="javascript:void(0);" class="icon_m04">매뉴얼</a></p>

	<div class="ipTop">
		<a href="/schedule/scheduleList/yymm/<?php echo $prev;?>" class="btn_arrow_prev"></a>
		<strong><?php echo $current_year;?> <span>/</span> <?php echo $current_month;?></strong>
		<a href="/schedule/scheduleList/yymm/<?php echo $next;?>" class="btn_arrow_next"></a>
	</div>

			<!--[s] 달력 -->
	<div class="eventList">
		<table cellspacing="0" summary="행사관리">
			<caption>행사관리</caption>
			<thead>
			<tr>
				<th scope="col" width="110" class="first"><img src="/theme/<?=$_theme?>/images/common/th_sun.gif" alt="일" /></th>
				<th scope="col" width="110"><img src="/theme/<?=$_theme?>/images/common/th_mon.gif" alt="월" /></th>
				<th scope="col" width="110"><img src="/theme/<?=$_theme?>/images/common/th_tue.gif" alt="화" /></th>
				<th scope="col" width="110"><img src="/theme/<?=$_theme?>/images/common/th_wed.gif" alt="수" /></th>
				<th scope="col" width="110"><img src="/theme/<?=$_theme?>/images/common/th_thu.gif" alt="목" /></th>
				<th scope="col" width="110"><img src="/theme/<?=$_theme?>/images/common/th_fri.gif" alt="금" /></th>
				<th scope="col" width="110"><img src="/theme/<?=$_theme?>/images/common/th_sat.gif" alt="토" /></th>
			</tr>
			</thead>
			<tbody>
			<?php 
				  // 5. 화면에 표시할 화면의 초기값을 1로 설정
			     $day=1;
			 
			    // 6. 총 주 수에 맞춰서 세로줄 만들기
			     for($i=1; $i <= $total_week; $i++){
			?> 
			<tr>
				 <?php
				  	for ($j=0; $j<7; $j++){
				 ?> 
				<td>
					<div class="boxArea">
						 <?php
					         // 8. 첫번째 주이고 시작요일보다 $j가 작거나 마지막주이고 $j가 마지막 요일보다 크면 표시하지 않아야하므로
					         //    그 반대의 경우 -  ! 으로 표현 - 에만 날자를 표시한다.
					         if (!(($i == 1 && $j < $start_week) || ($i == $total_week && $j > $last_week))){
					 
					            if($j == 0){
					                 // 9. $j가 0이면 일요일이므로 빨간색
					                 //echo "<font color='#FF0000'>";
					                 $css = 'sun';
					             }else if($j == 6){
					                 // 10. $j가 0이면 일요일이므로 파란색
					                 //echo "<font color='#0000FF'>";
					             	$css = 'sat';
					             }else{
					                 // 11. 그외는 평일이므로 검정색
					                 //echo "<font color='#000000'>";
					             	$css = 'day';
					             }
					 
					            // 12. 오늘 날자면 굵은 글씨
					            $view_day = ($day == date("j")) ? '<strong>'.$day.'</strong>' : $day;
					             
					            // 13. 날자 출력
					             $current_date = $param['yymm'].'-'.substr('0'.$day,-2);
					             echo '<span class="'.$css.'"><a href="javascript:register(\''.$param['yymm'].'-'.$day.'\')">'.$day.'</a></span>';
					             
					             if(is_array($_schedule)){
						             foreach($_schedule as $k => $v){
						             	if($_schedule[$k]['date'] == $current_date){
						             		$title = character_limiter($_schedule[$k]['title'],12);
						             		echo "<a href=\"javascript:modify('".$_schedule[$k]['id']."');\" title=\"{$_schedule[$k]['content']}\">
						             				{$title}
													<span class=\"time\">{$_schedule[$k]['time']}</span>
												</a>\n";
						             	}
						             }
					             }
					             
					            if($day == date("j")){
					                 //echo "</b>";
					             }
					 
					            //echo "</font>";
					 
					            // 14. 날자 증가
					             $day++;
					         }
			         ?>
					</div>
				</td>
				<?php 
				 	}
				?>
			</tr>
			<?php 
				}
			?>
			</tbody>
		</table>
	</div>
	<!--[e] 달력 -->

	<!--[s] Tip -->
	<dl id="tip" class="mt30">
		<dt>Tip</dt>
		<dd>인터넷익스플로러의 '호환성보기' 기능을 사용중인 접속자에게 자동으로 최신버전 기준으로 사이트를 출력하도록 처리합니다.</dd>
		<dd>코딩방식에 따라 특정 버전의 브라우저에서 사이트가 깨질수 있으니, 충분한 테스트 후 기능을 설정해 주시기 바랍니다.</dd>
	</dl>
	<!--[e] Tip -->
</div>

<!--[s] 행사관리 레이어 -->
<div id="layerBg"></div>
<div id="layerArea" class="layer_event">
	<div class="box_type02">
		<p class="layTit"><img src="/theme/<?php echo $_theme?>/images/common/ly_tit_event.gif" alt="행사관리" /></p>
		<p class="icon"><a href="javascript:closeLy();" class="icon_m05">닫기</a></p>

		<!--[s] 쓰기 -->
		<form name="frmReg" method="post" action="/schedule/scheduleDbjob">
		<input type="hidden" name="schedule_date">
		<input type="hidden" name="id" value="">
		<input type="hidden" name="dbjob" value="i">
		<fieldset class="board_write">
			<legend>행사관리</legend>
			<table cellspacing="0" summary="행사관리" class="lines">
				<caption>행사관리</caption>
				<tr>
					<th scope="row" width="130"><p class="point">제목</p></th>
					<td>
						<div>
							<input type="text" id="" name="title" class="ip_i" style="width:370px;" value="" />
						</div>
					</td>
				</tr>
				<tr>
					<th scope="row"><p class="point">시간</p></th>
					<td>
						<div>
							<input type="text" id="" name="schedule_time" class="ip_i" style="width:148px;" value="" />
						</div>
					</td>
				</tr>
				<!--<tr>
					<th scope="row"><p class="point">대상</p></th>
					<td>
						<div>
							<input type="text" id="" name="" class="ip_i" style="width:148px;" value="" />
						</div>
					</td>
				</tr>  -->
				<tr>
					<th scope="row"><p class="point">비고</p></th>
					<td>
						<div>
							<textarea name="content" rows="" cols="" class="ip_t" style="width:370px;"></textarea>
						</div>
					</td>
				</tr>
			</table>
		</fieldset>
		</form>
		<!--[e] 쓰기 -->

		<!-- [s] 버튼 -->
		<p class="tac mt30">
			<a href="javascript:frmValid();"><img src="/theme/<?=$_theme?>/images/common/btn_save.gif" alt="저장" /></a>
			<!-- <a href="javascript:void(0);"><img src="/theme/<?=$_theme?>/images/common/btn_modify.gif" alt="수정" /></a> -->
			<a href="javascript:frmDelete();" class="btnDelete"><img src="/theme/<?=$_theme?>/images/common/btn_delete.gif" alt="삭제" /></a>
		</p>
		<!-- [e] 버튼 -->
	</div>
</div>
<!--[e] 행사관리 레이어 -->